<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="检验单编号" prop="iqcCode">
        <el-input
          v-model="queryParams.osqcCode"
          placeholder="请输入外协检验单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产商编码" prop="manufactureCode">
        <el-input
          v-model="queryParams.manufactureCode"
          placeholder="请输入生产商编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产商名称" prop="manufactureName">
        <el-input
          v-model="queryParams.manufactureName"
          placeholder="请输入生产商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="批次号" prop="manufactureBatch">
        <el-input
          v-model="queryParams.manufactureBatch"
          placeholder="请输入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="产品物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入产品物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测结果" prop="checkResult">
        <el-select v-model="queryParams.checkResult" placeholder="请选择检测结果">
          <el-option
            v-for="dict in dict.type.mes_qc_result"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="检测人员" prop="inspector">
        <el-input
          v-model="queryParams.inspector"
          placeholder="请输入检测人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到货日期" prop="params">
        <el-date-picker
          clearable
          v-model="queryParams.params"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择到货日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检测日期" prop="params2">
        <el-date-picker
          clearable
          v-model="queryParams.params2"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择检测日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:qc:iqc:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:qc:iqc:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:qc:iqc:remove']"
        >删除</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes:qc:iqc:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="osqcList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="检验单编号" width="140px" align="center" prop="osqcCode" >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
            v-hasPermi="['mes:qc:osqc:query']"
          >{{scope.row.osqcCode}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="来料检验单名称" width="120px" align="center" prop="osqcName" :show-overflow-tooltip="true"/>
      <el-table-column label="生产商名称" width="100px" align="center" prop="manufactureName" :show-overflow-tooltip="true"/>
      <el-table-column label="批次号" width="120px" align="center" prop="manufactureBatch" :show-overflow-tooltip="true"/>
      <el-table-column label="产品物料编码" width="120px" align="center" prop="itemCode" :show-overflow-tooltip="true"/>
      <el-table-column label="产品物料名称" width="120px" align="center" prop="itemName" :show-overflow-tooltip="true"/>
      <el-table-column label="接收数量" width="90px" align="center" prop="quantityRecived">
        <template slot-scope="scope">
          <el-tag type="warning">{{ scope.row.quantityRecived }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="检测数量" width="80px" align="center" prop="quantityCheck" >
        <template slot-scope="scope">
          <el-tag >{{ scope.row.quantityCheck }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="不合格数" align="center" prop="quantityUnqualified" >
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.quantityUnqualified >0">{{ scope.row.quantityUnqualified }}</el-tag>
          <el-tag type="success" v-else>{{ scope.row.quantityUnqualified }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="到货日期" align="center" prop="reciveDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reciveDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测日期" align="center" prop="inspectDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inspectDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测人员" align="center" prop="inspector" />
      <el-table-column label="检测结果" width="90px" align="center" prop="checkResult" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_qc_result" :value="scope.row.checkResult"/>
        </template>
      </el-table-column>
      <el-table-column label="单据状态" align="center" prop="status" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180px">
        <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-printer"
              @click="handlePrint(scope.row)"
              v-hasPermi="['mes:qc:osqc:print']"
            >打印</el-button>
<!--          <el-tooltip content="修改" placement="top">
            <el-button
              size="mini"
              type="warning"
              icon="el-icon-edit"
              v-if="scope.row.status =='PREPARE'"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['mes:qc:iqc:edit']"
            ></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              v-if="scope.row.status =='PREPARE'"
              @click="handleDelete(scope.row)"
              v-hasPermi="['mes:qc:iqc:remove']"
            ></el-button>
          </el-tooltip>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改来料检验单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1080px" append-to-body>
      <div id="printArea">
      <el-form ref="form" :model="form"  disabled :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="检验单编号" prop="osqcCode">
              <el-input v-model="form.osqcCode" placeholder="请输入来料检验单编号" :readonly="optType === 'view'" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item  label-width="80">
              <el-switch v-model="autoGenFlag"
                  active-color="#13ce66"
                  active-text="自动生成"
                  @change="handleAutoGenChange(autoGenFlag)" v-if="optType != 'view' && form.status =='PREPARE'" >
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="检验单名称" prop="osqcName">
              <el-input v-model="form.osqcName" placeholder="请输入检验单名称" :readonly="optType === 'view'" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="3" align="middle">
              <el-image fit="contain" v-if="form.checkResult == 'ACCEPT'" :src="acceptImg" />
              <el-image fit="contain" v-else-if="form.checkResult == 'REJECT'" :src="rejectImg" />
              <el-image fit="contain" v-else :src="prepareImg" />
          </el-col>-->
        </el-row>
        <el-divider content-position="center">产品与生产商</el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item label="外协工单号" v-if="form.sourceDocType=='整单外协'"prop="sourceDocCode">
              <el-input v-model="form.sourceDocCode" readonly >
              </el-input>
            </el-form-item>
            <el-form-item label="外协订单号" v-if="form.sourceDocType=='工序外协'" prop="sourceDocCode">
              <el-input v-model="form.sourceDocCode" readonly >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工序编码" v-if="form.sourceDocType=='工序外协'"prop="taskCode">
              <el-input v-model="form.taskCode" readonly >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工序名称" v-if="form.sourceDocType=='工序外协'"prop="taskName">
              <el-input v-model="form.taskName" readonly >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品物料编码" prop="itemCode">
              <el-input v-model="form.itemCode" readonly >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品物料名称" prop="itemName">
              <el-input v-model="form.itemName" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input v-model="form.unitOfMeasure" readonly="readonly"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="生产商编码" prop="manufactureCode">
              <el-input v-model="form.manufactureCode" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产商名称" prop="manufactureName">
              <el-input v-model="form.manufactureName" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="批次号" prop="manufactureBatch">
              <el-input v-model="form.manufactureBatch" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">检测情况</el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item label="本次接收数量" prop="quantityRecived">
              <el-input v-model="form.quantityRecived" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本次检测数量" prop="quantityCheck">
              <el-input-number  :max="Number(form.quantityRecived)" v-model="form.quantityCheck" placeholder="请输入本次检测数量"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="不合格数量" prop="quantityUnqualified">
              <el-input-number :min="0"  :max="form.quantityCheck" v-model="form.quantityUnqualified" placeholder="请输入不合格数"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="到货日期" prop="reciveDate">
              <el-date-picker clearable
                              v-model="form.reciveDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择到货日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检测日期" prop="inspectDate">
              <el-date-picker clearable
                              v-model="form.inspectDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择检测日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="检测结果" prop="checkResult">
              <el-select v-model="form.checkResult" placeholder="请选择检测结果">
                <el-option
                  v-for="dict in dict.type.mes_qc_result"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="检测人员" prop="inspector">
              <el-input v-model="form.inspector" placeholder="请输入检测人员" readonly>
                <el-button slot="append" @click="handleSelectUser" icon="el-icon-search"></el-button>
              </el-input>
              <UserSelect ref="userSelect" @onSelected="onUserSelected" ></UserSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">统计结果</el-divider>
          <el-row>
            <el-col :span="8">
              <el-form-item label="致命缺陷率" prop="crRate">
                <el-input v-model="form.crRate" readonly="readonly" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="严重缺陷率" prop="majRate">
                <el-input v-model="form.majRate" readonly="readonly" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="轻微缺陷率" prop="minRate">
                <el-input v-model="form.minRate" readonly="readonly" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="致命缺陷数量" prop="crQuantity">
                <el-input v-model="form.crQuantity" readonly="readonly" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="严重缺陷数量" prop="majQuantity">
                <el-input v-model="form.majQuantity" readonly="readonly" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="轻微缺陷数量" prop="minQuantity">
                <el-input v-model="form.minQuantity" readonly="readonly" />
              </el-form-item>
            </el-col>
          </el-row>
        <el-divider v-if="form.osqcId !=null&&form.sourceDocType=='整单外协'" content-position="center">检测项</el-divider>
        <el-card shadow="always" v-if="form.osqcId !=null&&form.sourceDocType=='整单外协'" class="box-card">
          <OsqcLine ref=line :osqcId="form.osqcId" @handleReview="handleReview"></OsqcLine>
        </el-card>
      </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel" v-if="optType =='view' || form.status !='PREPARE' ">返回</el-button>
        <el-button type="primary" @click="print" v-if=" printPage ">打印</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import printJS from "print-js";
import { listOsqc, getOsqc } from "@/api/mes/qc/osqc";
import OsqcLine from "./osqcline.vue";
import {genCode} from "@/api/system/autocode/rule"
import {getReport,getReport2} from "@/api/mes/report/report"
import UserSelect from "@/components/userSelect/single.vue";
export default {
  name: "Osqc",
  dicts: ['mes_qc_result','mes_order_status'],
  components: { OsqcLine, UserSelect,printJS, },
  data() {
    return {
      //自动生成编码
      autoGenFlag:false,
      optType: undefined,
      printPage:false,
      acceptImg:  require('@/assets/images/accept.png'),
      rejectImg: require('@/assets/images/reject.png'),
      prepareImg: require('@/assets/images/prepare.png'),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 来料检验单表格数据
      osqcList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        osqcCode: null,
        osqcName: null,
        templateId: null,
        manufactureId: null,
        manufactureCode: null,
        manufactureName: null,
        manufactureNick: null,
        manufactureBatch: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        specification: null,
        unitOfMeasure: null,
        quantityMinCheck: null,
        quantityMaxUnqualified: null,
        quantityRecived: null,
        quantityCheck: null,
        quantityUnqualified: null,
        crRate: null,
        majRate: null,
        minRate: null,
        crQuantity: null,
        majQuantity: null,
        minQuantity: null,
        checkResult: null,
        reciveDate: null,
        inspectDate: null,
        inspector: null,
        status: null,
        params: [],
        params2: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        osqcCode: [
          { required: true, message: "外协检验单编号不能为空", trigger: "blur" }
        ],
        manufactureCode: [
          { required: true, message: "供应商不能为空", trigger: "blur" }
        ],
        itemCode: [
          { required: true, message: "物料不能为空", trigger: "blur" }
        ],
        quantityRecived: [
          { required: true, message: "本次接收数量不能为空", trigger: "blur" }
        ],
        quantityCheck: [
          { required: true, message: "本次检测数量不能为空", trigger: "blur" }
        ],
        reciveDate:[
          { required: true, message: "清选择来料日期", trigger: "blur" }
        ],
        inspectDate:[
          { required: true, message: "清选择检验日期", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    print() {
      printJS({
        type: 'html',
        printable: 'printArea',
        documentTitle: '外协检验单',
        header: '外协检验单',
        // 写入自定义样式
        headerStyle: 'text-align:center;width:100%;margin-top:25px;font-weight: 300;',
        style: `@page {
                  size: A4 landscape !important; /* 强制 A4 横向 */
                  margin: 2cm 1.5cm 2cm 1.5cm !important; /* 上右下左边距 */
                }
                @media print {
                  body {
                      -webkit-print-color-adjust: exact !important; /* 让颜色更准确 */
                      print-color-adjust: exact !important;
                  }
                  .section {
                    break-inside: avoid !important;
                  }
                  .el-form-item__content, .el-table .cell {
                    white-space: nowrap; /* 不允许文本换行 */
                    overflow: hidden; /* 超出部分隐藏 */
                    text-overflow: ellipsis; /* 超出部分用省略号表示 */
                  }
                  .el-table td, .el-table th {
                    box-sizing: border-box;
                    text-overflow: ellipsis;
                    vertical-align: middle;
                    position: relative;
                    padding: 0;
                    height: 70px; /* 增加高度 */
                    max-height: 70px;
                  }
                  .statistic-section, .inspection-section {
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    margin-bottom: 20px; /* 增加段落间距 */
                  }
                  .el-divider__text {
                    white-space: nowrap !important; /* 强制不换行 */
                    overflow: hidden; /* 超出部分隐藏 */
                    text-overflow: ellipsis; /* 超出部分用省略号表示 */
                    display: inline-block; /* 确保为行内块级元素 */
                    max-width: 100%; /* 最大宽度为100% */
                  }
                  .el-divider {
                    width: 100%; /* 确保 divider 宽度为100% */
                    margin: 20px 0; /* 上下外边距 */
                  }
                  .el-divider--horizontal {
                    border: 1px solid;
                    height: 2px;
                  }
                }
                .divider {
                  display: flex; /* 使用Flexbox布局 */
                  align-items: center; /* 垂直居中对齐 */
                  margin: 20px 0; /* 上下外边距 */
                }

                .divider::before,
                .divider::after {
                  content: ""; /* 伪元素内容为空 */
                  flex: 1; /* 伸展占据剩余空间 */
                  border-top: 1px solid #d3d3d3; /* 灰色的上边线 */
                }
                .label {
                  display: flex;
                  padding: 10px 10px !important;
                  border: 1px solid #d3d3d3; /* 蓝色边框 */
                  border-radius: 10px; /* 圆角 */
                  background-color: #fff; /* 白色背景 */
                  color: #1b9aee; /* 蓝色字体 */
                  font-family: "苹方 常规", "苹方", sans-serif;
                  font-weight: 700;
                  font-style: normal;
                  font-size: 24px;
                  text-align: center;
                  line-height: 20px;
                }
                .noprint{
                  display:none !important;
                }`,
        scanStyles: true,
        // 继承样式
        targetStyles: ['*'],
        maxWidth: 1960
      });
    },
    /** 查询来料检验单列表 */
    getList() {
      this.loading = true;
      const query = { ...this.queryParams };
      if (query.params && query.params.length === 2) {
        query.params = {
          beginTime: query.params[0],
          endTime: query.params[1]
        };
      } else {
        query.params = null;
      }
      if (query.params2 && query.params2.length === 2) {
        query.params2 = {
          beginTime: query.params2[0],
          endTime: query.params2[1]
        };
      } else {
        query.params2 = null;
      }
      listOsqc(query).then(response => {
        this.osqcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        osqcId: null,
        osqcCode: null,
        osqcName: null,
        templateId: null,
        manufactureId: null,
        manufactureCode: null,
        manufactureName: null,
        manufactureNick: null,
        manufactureBatch: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        specification: null,
        unitOfMeasure: null,
        quantityMinCheck: null,
        quantityMaxUnqualified: null,
        quantityRecived: null,
        quantityCheck: null,
        quantityUnqualified: null,
        crRate: null,
        majRate: null,
        minRate: null,
        crQuantity: null,
        majQuantity: null,
        minQuantity: null,
        checkResult: null,
        reciveDate: null,
        inspectDate: null,
        inspector: null,
        status: "PREPARE",
        remark: null,
        attr1: null,
        attr2: null,
        attr3: null,
        attr4: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.printPage=false;
      this.autoGenFlag = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.iqcId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
   /* handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加来料检验单";
      this.optType = 'add';
    },*/
    //查看明细
    handleView(row){
      this.reset();
      const osqcId = row.osqcId || this.ids;
      getOsqc(osqcId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看外协检验单信息";
        this.optType = "view";
      });
    },
    //查看明细
    handlePrint(row){
      this.reset();
      const osqcId = row.osqcId || this.ids;
      getOsqc(osqcId).then(response => {
        this.form = response.data;
        this.printPage=true;
        this.open = true;
        this.title = "打印外协检验单信息";
        this.optType = "view";
      });
    },

    /** 修改按钮操作 */
    /*handleUpdate(row) {
      this.reset();
      const iqcId = row.iqcId || this.ids
      getIqc(iqcId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改来料检验单";
        this.optType = 'edit';
      });
    },*/
   /* /!** 提交按钮 *!/
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.iqcId != null) {
            updateIqc(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              //this.open = false;
              this.getList();
            });
          } else {
            addIqc(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              //this.open = false;
              this.form.iqcId=response.data;
              this.getList();
            });
          }
        }
      });
    },*/
    //点击完成
   /* handleFinish(){
      let that = this;
      if(this.form.checkResult == null){
        this.$modal.msgError("请选择检测结果！");
        return;
      }

      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$modal.confirm('是否完成来料检验单编制？【完成后将不能更改】').then(function(){
            if(that.form.sourceDocId && that.form.sourceDocCode && that.form.sourceLineId){
              that.form.status = 'FINISHED';
            }else{
              that.form.status = 'CONFIRMED';
            }

            that.submitForm();
            that.open = false;
          });
        }
        });
    },*/
    /** 删除按钮操作 */
    /*handleDelete(row) {
      const iqcIds = row.iqcId || this.ids;
      this.$modal.confirm('是否确认删除来料检验单编号为"' + iqcIds + '"的数据项？').then(function() {
        return delIqc(iqcIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },*/
    /** 导出按钮操作 */
    /*handleExport() {
      this.download('qc/osqc/export', {
        ...this.queryParams
      }, `外协质检_${new Date().getTime()}.xlsx`)
    },*/
    handleSelectProduct(){
      this.$refs.itemSelect.showFlag = true;
    },
    //物料选择弹出框
    onItemSelected(obj){
        if(obj != undefined && obj != null){
          this.form.itemId = obj.itemId;
          this.form.itemCode = obj.itemCode;
          this.form.itemName = obj.itemName;
          this.form.specification = obj.specification;
          this.form.unitOfMeasure = obj.unitOfMeasure;
          this.form.manufactureId = obj.vendorId;
          this.form.manufactureCode = obj.vendorCode;
          this.form.manufactureName = obj.vendorName;
          this.form.manufactureNick = obj.vendorNick;
          this.form.manufactureBatch=obj.batchCode;
          this.form.quantityRecived = obj.quantityRecived;
          this.form.reciveDate=obj.recptDate;
        }
    },
    //自动生成编码
    handleAutoGenChange(autoGenFlag){
      if(autoGenFlag){
        genCode('QC_OSQC_CODE').then(response =>{
          this.form.osqcCode = response;
        });
      }else{
        this.form.osqcCode = null;
      }
    },
    viewReport(){
      var reportName = "Test";
      getReport2(reportName).then(res=>{
        let blob = new Blob([res],{type:'application/pdf'});
        let href = URL.createObjectURL(blob);
        console.log(href);
        window.open(`/pdf/web/viewer.html?file=${encodeURIComponent(href)}`);
      });
    },
    handleReview() {
      getOsqc(this.form.osqcId).then(response => {
        this.form.crRate=response.data.crRate;
        this.form.majRate=response.data.majRate;
        this.form.minRate=response.data.minRate;
        this.form.crQuantity=response.data.crQuantity;
        this.form.majQuantity=response.data.majQuantity;
        this.form.minQuantity=response.data.minQuantity;
      });
    },
    handleSelectUser(){
      this.$refs.userSelect.showFlag = true;
    },
    // 用户选择弹出框
    onUserSelected(obj){
      if(obj != undefined && obj != null){
        this.form.inspector = obj.nickName;
      }
    },
  }
};
</script>
<style scoped>
@media print {
  .el-input.is-disabled .el-input__inner {
    /* background-color: #F5F7FA; */
    /* border-color: #dfe4ed; */
    color: #C0C4CC;
    cursor: not-allowed;
    border: none;
    background: none;
  }
}
#printArea{
  margin: 0 auto;
}
#printArea .el-divider--horizontal {
  border-bottom: 1px solid #DCDFE6;
}

</style>
